package com.ncepu.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
//import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class CaffeineConfig {

    @Bean(name = "userCaffeineCache")
    public Cache<Integer, String> caffeineCache() {
        return Caffeine.newBuilder()
                .initialCapacity(1024)
                .maximumSize(10000L)
                .expireAfterWrite(5, TimeUnit.MINUTES)
                .recordStats()
                .build();
    }

    @Bean(name = "userGuavaCache")
    public com.google.common.cache.Cache<Integer, String> guavaCache() {
        com.google.common.cache.Cache<Integer, String> guavaCache = CacheBuilder.newBuilder()
                .build(new com.google.common.cache.CacheLoader<Integer, String>() {
                    @Override
                    public String load(Integer key) throws Exception {
                        return "user" + key;
                    }
                });
        return guavaCache;
    }
}
